package cn.tedu._07weibo.base.interceptors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import java.time.LocalDateTime;

@Slf4j
public class TimeInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入限定访问拦截器...");
        LocalDateTime now=LocalDateTime.now();
        int hour =now.getHour();
        if (hour<6 || hour>22){
            throw new RuntimeException("请在6：00-23：00之间访问该网页");
        }
        return true;
    }
}
